<template>
	<view>
		<u-datetime-picker :show="messageTime.timeShow" v-model="value1" :title="messageTime.title"
			:mode="messageTime.mode" @cancel="cancel" :minDate="minDate" @confirm="confirm"></u-datetime-picker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		// 使用示例
		// <timePicker :messageTime="messageTime" @timeConfirm="timeConfirm"></timePicker>
		// messageTime:{
		// 	timeShow:false,
		// 	title:"选择出生年月",
		// 	mode:"date"//date日期，datetime年月日时分秒，time时间
		// }
		// timeConfirm(e){
		// 	this.time = e
		// },
		name: "timePicker",
		props: {
			messageTime: {}
		},
		data() {
			return {
				value1: Number(new Date()),
				minDate: "",
			};
		},
		created() {
			this.minDate = Number(new Date('1950-01-01'));
		},
		methods: {
			confirm(e) {
				if (this.messageTime.mode == "date") { //年月日
					this.$emit("timeConfirm", httpRequest.returnDate(e.value))
				} else if (this.messageTime.mode == "datetime") { //年月日时分秒
					this.$emit("timeConfirm", this.timereturn(e.value))
				} else if (this.messageTime.mode == "time") { //时分
					this.$emit("timeConfirm", e.value)
				}
				this.messageTime.timeShow = false
			},
			cancel(e) {
				this.messageTime.timeShow = false
			},
			timereturn(time3) {
				//将时间戳格式转换成年月日时分秒
				var date = new Date(time3);
				var Y = date.getFullYear() + '-';
				var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';

				var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
				var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
				var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
				var strDate = Y + M + D + h + m + s;
				return strDate

			},
		}
	}
</script>

<style>

</style>